package org.broadway.monitor.dsl;


/**
 * BinaryCondition is a Conditional which evaluates its
 * expression to either True or False.  This class also 
 * uses a textual expression to expression the condition to 
 * evaluate.
 * 
 * @author vladimir vivien
 * @see Conditional
 * @see When
 * @see MonitorDsl
 */
public class BinaryCondition implements Conditional<String> {
	private String expression;
	private boolean execWhen;
	
	/**
	 * Constructor that accepts the conitional expression.
	 * @param expression
	 */
	public BinaryCondition (String expression) {
		this.setExpression(expression);
	}
	

	/**
	 * The textual expression that will be evaluated for the
	 * conditional.
	 */
	public Conditional setExpression(String exp) {
		expression = exp;
		return this;
	}
	/**
	 * A getter that returns the expression.
	 * @return String - expression
	 */
	public String getExpression() {
		return expression;
	}
	
	/**
	 * BinaryCondition allows user to determine when the 
	 * action will be executed based on the result of the evaluation of the expression.
	 * Use this method to establish a boolean flag that indicates when to execute the
	 * action.
	 * @param flag - Boolean flag [true=Action will be executed when expression evaluates to True,
	 *               false=Action will be executed when expression evaluates to false].
	 * @return BinaryCondition
	 */
	public Conditional setExecWhen(boolean flag){
		execWhen = flag;
		return this;
	}
	/**
	 * Getter which returns the flag for action execution trigger.
	 * @return
	 */
	public boolean getExecWhen() {
		return execWhen;
	}

}
